import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;


public class FileSystemStorage implements Storage {
	private String relBaseName;
	
	public FileSystemStorage(String relBaseName) {
		this.relBaseName = relBaseName;
	}

	public FileSystemStorage(int foo, int bar) {
		this.relBaseName = "tests/";
	}

	@Override
	public void reset() throws IOException {
	}
	
	@Override
	public OutputStream getOutputStream(int num) throws IOException {
		File file = new File(relBaseName + num +".bin");
		return new FileOutputStream(file.getAbsoluteFile());
	}

	@Override
	public InputStream getInputStream(int num) throws IOException {
		File file = new File(relBaseName + num +".bin");
		return new FileInputStream(file.getAbsoluteFile());
	}
	
	public long bitLength(int num) throws IOException {
		FileInputStream fos = null;
		try {
			fos = new FileInputStream(relBaseName + num +".bin");
			return fos.available() * 8;
		} finally {
			if (fos != null) {
				fos.close();
			}
		}
	}

}
